package com.course.cdspringboot.mapper.achievement;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.course.cdspringboot.entity.achievement.AchievementPaper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AchievementPaperMapper extends BaseMapper<AchievementPaper> {

    @Select("SELECT count(*) FROM achievement_paper WHERE paper_name = #{paper_name}")
    int countByPaperName(String paper_name);

    @Select("<script>" +
            "SELECT achievement_paper.*, review_status.name review_status, achievements.created_date, achievements.review_comments " +
            "FROM achievement_paper " +
            "JOIN achievements ON achievement_paper.achievement_id = achievements.achievement_id " +
            "JOIN review_status ON achievements.review_status_id = review_status.id " +
            "WHERE achievements.is_deleted=false AND achievement_paper.achievement_id IN " +
            "<foreach item='item' index='index' collection='ids' " +
            "open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<AchievementPaper> selectByAchievementIds(@Param("ids") List<Integer> ids);


//    // 查询论文
//    @Select("SELECT achievement_paper.*, achievements.review_status_id, achievements.created_date " +
//            "FROM achievement_paper " +
//            "JOIN achievements ON achievement_paper.achievement_id = achievements.achievement_id " +
//            "WHERE achievement_paper.achievement_id IN (#{ids})")
//    List<AchievementPaper> selectByAchievementIds(@Param("ids") List<Integer> ids);

//    @Select("SELECT * from achievement_paper " +
//            "where achievement_paper.achievement_id in " +
//            "(select achievement_id from achievements " +
//            "where Owner=#{uid})")
//    List<AchievementPaper> selectMyPaper(Long uid);

//    // 插入论文
//    @Insert("INSERT INTO achievement_paper (achievement_id, paper_name, journal, issue, volume, page, " +
//            "retrieval_level, author_list, first_author, corresponding_author, publication_date, " +
//            "impact_factor, paper_link, submission_date) " +
//            "VALUES (#{achievement_id}, #{paper_name}, #{journal}, #{issue}, #{volume}, #{page}, " +
//            "#{retrieval_level}, #{author_list}, #{first_author}, #{corresponding_author}, #{publication_date}, " +
//            "#{impact_factor}, #{paper_link}, #{submission_date})")
//    void insert(Map<String, Object> achievementPaper);
//
//    // 更新论文
//    @Update("UPDATE achievement_paper " +
//            "SET paper_name = #{paper_name}, " +
//            "    journal = #{journal}, " +
//            "    issue = #{issue}, " +
//            "    volume = #{volume}, " +
//            "    page = #{page}, " +
//            "    retrieval_level = #{retrieval_level}, " +
//            "    author_list = #{author_list}, " +
//            "    first_author = #{first_author}, " +
//            "    corresponding_author = #{corresponding_author}, " +
//            "    publication_date = #{publication_date}, " +
//            "    impact_factor = #{impact_factor}, " +
//            "    paper_link = #{paper_link}, " +
//            "    submission_date = #{submission_date} " +
//            "WHERE achievement_id = #{achievement_id} AND " +
//            "achievement_id IN (SELECT achievement_id FROM achievements WHERE Owner=#{uid});")
//    void update(Map<String, Object> achievement_paper_info);

}
